from langchain_huggingface import HuggingFaceEmbeddings
from tqdm import tqdm_notebook as tqdm

model_name = "BAAI/bge-large-zh-v1.5"
# 根据你的需要去选择设备
model_kwargs = {'device': 'cpu'}
encode_kwargs = {'normalize_embeddings': True}
# 初始化模型（以 BGE 为例）
model = HuggingFaceEmbeddings.from_model_name(
    model_name=model_name,
    model_kwargs={"device": "cpu"},  # 可选 "cuda" 使用 GPU
    encode_kwargs=encode_kwargs,
    query_instruction="为这个句子生成表示以用于检索相关文章："
)
model.query_instruction = "为这个句子生成表示以用于检索相关文章："